/*
 * 物资出售列表
 * @Author: ljb
 * @Date: 2018-07-12 10:00:37
 * @Last Modified by: ljb
 * @Last Modified time: 2018-09-26 18:08:36
 */
<template>
	<div class="v-admin-material-sold-index">

		<Table
			:columns="columns"
			:loading="loading"
			:data="materials"
			:height="tableHeight()"
			border
			class="personal-scrollbar"
			@on-sort-change="sortable"/>

	</div>
</template>

<script>
import { computedTableHeight } from 'src/views/mixins/computedTableHeight';

export default {
	name: 'SuppliesSoldIndex',
	mixins: [computedTableHeight],
	props: {
		loading: {
			type: Boolean,
			default() {
				return false;
			},
		},
		materials: {
			type: Array,
			default() {
				return [];
			},
		},
	},

	data() {
		return {
			columns: [
				{
					title: this.$t('supplies_management.name'),
					key: 'name',
					align: 'center',
					render: (h, { row }) => <div> { row.material_purchase.material.name || '-' } </div>,
				},
				{
					title: this.$t('supplies_management.sold_num'),
					key: 'num',
					align: 'center',
					sortable: 'custom',
					render: (h, { row }) => <div> { row.num || '-' } </div>,
				},
				{
					title: this.$t('supplies_management.customer'),
					key: 'customer',
					align: 'center',
					render: (h, { row }) => <div> { row.customer.name || '-' } </div>,
				},
				{
					title: this.$t('supplies_management.operator'),
					key: 'operator',
					align: 'center',
					render: (h, { row }) => <div> { row.operator || '-' } </div>,
				},
				{
					title: this.$t('supplies_management.remark'),
					key: 'remark',
					align: 'center',
					render: (h, { row }) => <div> { row.remark || '-' } </div>,
				},
				{
					title: this.$t('supplies_management.sold_date'),
					key: 'sold_at',
					align: 'center',
					sortable: 'custom',
					render: (h, { row }) => <div> { row.sold_at || '-' } </div>,
				},
			],
		};
	},

	methods: {

		/**
         * 排序的回调
         * @param  {Object} param {对应列的属性对象,里面包含了column列属性，key值，order排序字段}
         * @return {undefined}
         */
		sortable(param) {
			const search_param = {
				order_by: param.order === 'normal' ? '' : param.key,

				sort: param.order === 'normal' ? '' : param.order.toLocaleUpperCase(),
			};

			this.$emit('sort', search_param);
		},

	},
};
</script>
